package com.fileshare.web.controller.index.api;


import com.fileshare.web.dto.Bo.CommentBo;
import com.fileshare.web.dto.Result;
import com.fileshare.web.dto.Vo.CommentVo;
import com.fileshare.web.service.CommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 评论模块的api
 */
@RestController
@RequestMapping("/api/comment")
public class CommentApiController {
    @Resource
    private CommentService commentService;

    @PostMapping("")
    @PreAuthorize("@auth.matchAny('commentator:create')")
    public Result<CommentVo> createComment(HttpServletRequest request, @RequestBody CommentBo commentBo) {
        CommentVo commentVo = commentService.createComment(request, commentBo);
        return Result.success().with(commentVo);
    }
}
